package com.kuzlak.cms.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuzlak.cms.bean.MyPage;
import com.kuzlak.cms.module.sys.entity.SysOperationLog;
import com.kuzlak.cms.module.sys.mapper.SysOperationLogMapper;
import com.kuzlak.cms.module.sys.service.SysOperationLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author hesenjan
* @description 针对表【sys_operation_log】的数据库操作Service实现
* @createDate 2024-11-30 23:46:05
*/
@Service
public class SysOperationLogServiceImpl extends ServiceImpl<SysOperationLogMapper, SysOperationLog>
    implements SysOperationLogService{
    @Override
    public MyPage findByPage(int pagesize, int page, int type, int status, String startDate, String endDate, String requestUrl, String requestMode) {
        MyPage page1 = new MyPage();
        QueryWrapper<SysOperationLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("ID");

        if (StringUtils.isNotEmpty(requestUrl)) {
            queryWrapper.lambda().likeRight(SysOperationLog::getRequestUrl, requestUrl);
        }

        if (StringUtils.isNotEmpty(requestMode)) {
            queryWrapper.lambda().likeRight(SysOperationLog::getRequestMode, requestMode);
        }
        if (StringUtils.isNotEmpty(startDate)) {
            queryWrapper.apply(StringUtils.isNotBlank(startDate), "DATE(DATE)>=DATE_FORMAT('" + startDate + "','%Y-%m-%d')");
        }

        if (StringUtils.isNotEmpty(endDate)) {
            queryWrapper.apply(StringUtils.isNotBlank(endDate), "DATE(DATE)<=DATE_FORMAT('" + endDate + "','%Y-%m-%d')");
        }

        if (status > 0) {
            queryWrapper.lambda().eq(SysOperationLog::getStatus, status);
        }
        if (type > 0) {
            queryWrapper.lambda().eq(SysOperationLog::getType, type);
        }


        Page<SysOperationLog> page0 = new Page<>(page, pagesize);
        IPage<SysOperationLog> data = this.getBaseMapper().selectPage(page0, queryWrapper);
return  MyPage.parsePage(data);
    }
}









